#include<bits/stdc++.h>
using namespace std;
int n,m,cnt,a[200005],c[200005];
int main(){
freopen("color.in","r",stdin);
freopen("color.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++){
cnt=0;
cin>>m;
for(int j=1;j<=m;j++){
cin>>a[j];
c[j]=0;
}
sort(a+1,a+1+m);
for(int j=2;j<=m;j++){
if(a[j-1]==a[j])
c[j]=a[j];
cnt+=c[j];
}
cout<<cnt<<endl;
}
return 0;
}
